﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;

namespace Aspire.App
{
    public class NagivateBehavior : Behavior<RadMenu>
    {

        protected override void OnAttached()
        {
            base.OnAttached();
            this.AssociatedObject.ItemClick += AssociatedObject_ItemClick;
        }

        void AssociatedObject_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            RadMenuItem menuItem = e.Source as RadMenuItem;

            if (menuItem != null && menuItem.DataContext is Function)
            {
                Function func = menuItem.DataContext as Function;
                if (AspireFramework.Instance.Frame != null)
                {
                    AspireFramework.Instance.Frame.Navigate(new Uri(func.NavigateUri, UriKind.RelativeOrAbsolute));
                }
            }
            return;
        }
        protected override void OnDetaching()
        {
            base.OnDetaching();
            this.AssociatedObject.ItemClick -= AssociatedObject_ItemClick;
        }

    }

}
